using System.Linq;
using UnityEngine;
using UnityEngine.UI;

namespace MaterialUI
{
	public class TabViewInstantiationHelper : InstantiationHelper
	{
		public const int optionHasIcon = 0;

		public const int optionHasLabel = 1;

		[SerializeField]
		private RectTransform m_RectTransform;

		[SerializeField]
		private TabItem m_ItemTemplate;

		[SerializeField]
		private RectTransform m_TabBarRectTransform;

		[SerializeField]
		private RectTransform m_PagesRectTransform;

		[SerializeField]
		private RectTransform[] m_IconRectTransforms;

		[SerializeField]
		private RectTransform m_TextRectTransform;

		public override void HelpInstantiate(int[] options)
		{
			m_RectTransform.sizeDelta = Vector2.zero;
			m_RectTransform.anchoredPosition = Vector2.zero;
			if (!options.Contains(0) || !options.Contains(1))
			{
				RectTransform tabBarRectTransform = m_TabBarRectTransform;
				Vector2 sizeDelta = m_TabBarRectTransform.sizeDelta;
				tabBarRectTransform.sizeDelta = new Vector2(sizeDelta.x, 48f);
				if (!options.Contains(0))
				{
					m_ItemTemplate.itemIcon = null;
					for (int i = 0; i < m_IconRectTransforms.Length; i++)
					{
						UnityEngine.Object.DestroyImmediate(m_IconRectTransforms[i].gameObject);
					}
					m_TextRectTransform.anchorMin = Vector2.zero;
					m_TextRectTransform.anchorMax = Vector2.one;
					m_TextRectTransform.anchoredPosition = Vector2.zero;
					m_TextRectTransform.sizeDelta = Vector2.zero;
					m_TextRectTransform.GetComponent<Text>().alignment = TextAnchor.MiddleCenter;
				}
				else
				{
					m_ItemTemplate.itemText = null;
					UnityEngine.Object.DestroyImmediate(m_TextRectTransform.gameObject);
					for (int j = 0; j < m_IconRectTransforms.Length; j++)
					{
						m_IconRectTransforms[j].anchorMin = new Vector2(0.5f, 0.5f);
						m_IconRectTransforms[j].anchorMax = new Vector2(0.5f, 0.5f);
						m_IconRectTransforms[j].pivot = new Vector2(0.5f, 0.5f);
						m_IconRectTransforms[j].anchoredPosition = Vector2.zero;
						m_IconRectTransforms[j].sizeDelta = new Vector2(24f, 24f);
					}
				}
				RectTransform pagesRectTransform = m_PagesRectTransform;
				Vector2 sizeDelta2 = m_PagesRectTransform.sizeDelta;
				pagesRectTransform.sizeDelta = new Vector2(sizeDelta2.x, -48f);
				RectTransform pagesRectTransform2 = m_PagesRectTransform;
				Vector2 anchoredPosition = m_PagesRectTransform.anchoredPosition;
				pagesRectTransform2.anchoredPosition = new Vector2(anchoredPosition.x, -24f);
			}
			base.HelpInstantiate(options);
		}
	}
}
